#pragma once
#include"protocol.hpp"

class calculator
{
public:
    calculator(){}
    respond calculate(request &rq)
    {
        respond ret;
        switch(rq.OPER())
        {
            case '+':
                ret.ANS()=rq.X()+rq.Y();
                ret.CODE()=0;
                break;
            case '-':
                ret.ANS()=rq.X()-rq.Y();
                ret.CODE()=0;
                break;
            case '*':
                ret.ANS()=rq.X()*rq.Y();
                ret.CODE()=0;
                break;
            case '/':
                if(rq.Y()==0){
                    ret.CODE()=DIV_ZERO_ERROR;
                    break;
                }
                ret.ANS()=rq.X()/rq.Y();
                ret.CODE()=0;
                break;
            case '%':
                if(rq.Y()==0){
                    ret.CODE()=DIV_ZERO_ERROR;
                    break;
                }
                ret.ANS()=rq.X()%rq.Y();
                ret.CODE()=0;
                break;
            default:
                ret.CODE()=OPER_ERROR;
        }
        return ret;
    }
    ~calculator(){}
};